programming4us
           
 
 
Programming

Coding JavaScript for Mobile Browsers (part 1) - Code Execution

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
12/24/2010 2:41:56 PM
First of all, let’s see what is happening with basic JavaScript compatibility (variables, functions and basic alert functionality) with mobile browsers. Table 1 illustrates the current levels of support on the different platforms.
Table 1. JavaScript support compatibility table
Browser/platformJavaScript support
SafariYes
Android browserYes
Symbian/S60Yes
Nokia Series 40Yes
webOSYes
BlackBerryYes from 3.8 Can be disabled by the user or the company; in that case, noscript is executed
NetFrontYes
Openwave (Myriad)Not available in Openwave; yes in Myriad Browser V7
Internet ExplorerYes
Motorola Internet BrowserYes
Opera MobileYes
Opera MiniYes, but everything after the onload script will be executed on the server, generating a postback


Note:

As Openwave does not support JavaScript and Myriad 7 is not commonly found on mobile devices today (making testing difficult), Openwave/Myriad will be left out of the following JavaScript-related tables.


We need to pay special attention to proxied browsers, like Opera Mini. Remember that these browsers render our websites on their servers and send compressed and compiled content to the clients. The clients aren’t really browsers capable of rendering an XHTML file or JavaScript code.


Note:

For old non-JavaScript mobile browsers or for browsers with JavaScript disabled, we can use the noscript tag. Only those browsers will display its content.


When we talk about mobile JavaScript, we are talking about the same code you already know: a script tag including some code or a script tag with an external source. Many browsers accept the old way of defining the script language (language="javascript"), and many of them also accept not defining the language at all (using script alone):

<script type="text/javascript">
// Code goes here
</script>

<script src="mysource.js" type="text/javascript">


Note:

ECMAScript Mobile Profile defines two new types for the script tag, application/ecmascript and text/ecmascript, as the preferred types to use for ESMP-compatible code. Beyond that, text/javascript is the recommendation for XHTML MP documents and is the most compatible type to use for non-MP browsers. My recommendation is to carry on using the well-known text/javascript.


1. Code Execution

You can execute JavaScript code in four different ways:

  • From a script tag

  • From an event handler

  • From a link using the javascript: URL protocol

  • From a bookmarklet using the javascript: URL protocol

Bookmarklets

A bookmarklet is a bookmark in the browser containing some JavaScript code using a javascript: protocol URL. When the user activates the bookmark, the JavaScript code is executed over the current document. This allows us to execute a wide range of testing, debugging, and other features over any web page.

There are bookmarklets on the Web that are large applications, encoded in a single line of JavaScript. One of my favorites for desktop usage is Readability (http://lab.arc90.com/experiments/readability).

The main problem with bookmarklets in mobile devices is how to add them. In the desktop web, the main way is to drag a link with the JavaScript code to the bookmarks area. This cannot be done in a mobile device, though, so bookmarklets are only useful if you can manage or synchronize them from a desktop (e.g., via iTunes for iPhone).

There are a lot of bookmarklets for iPhone on the Web, including some that will show the source code of the page inside the mobile browser. These are only really useful for testing or debugging purposes, though, or for “only geek” features.


Table 2 shows which of these work with which browsers.

Table 2. Script execution compatibility table
Browser/platformScriptEvent handlerURL
SafariYesYesYes
Android browserYesYesYes
Symbian/S60YesYesYes
Nokia Series 40YesNo before 6th editionYes
webOSYesYesYes
BlackBerryYesNo before 4.6Yes
NetFrontYesYesYes
Internet ExplorerYesPartialYes
Motorola Internet BrowserYesNoYes
Opera MobileYesYesYes
Opera MiniYesNoNo


Note:

If a device is not compatible with JavaScript (different from a device that is compatible but has JavaScript disabled), it will show the JavaScript code to the user as text. We can avoid this problem by inserting an HTML comment just after the script tag:

<script type="text/javascript">
<!--
// JavaScript code here
-->
</script>
Other -----------------
- Programming the Mobile Web : JavaScript Mobile - Supported Technologies
- Security in Cloud Computing (part 4) - Audit and Compliance
- Security in Cloud Computing (part 3)
- Security in Cloud Computing (part 2) - Identity and Access Management
- Security in Cloud Computing (part 1) - Data Security and Storage
- Cloud Security and Privacy : Analyst Predictions
- CSS for Mobile Browsers : WebKit Extensions (part 2) - Border Image
- CSS for Mobile Browsers : WebKit Extensions (part 1) - Text Stroke and Fill
- jQuery 1.3 : Working with numeric form data (part 9) - The finished code
- jQuery 1.3 : Working with numeric form data (part 8) - Editing shipping information
- jQuery 1.3 : Working with numeric form data (part 7) - Deleting items
- jQuery 1.3 : Working with numeric form data (part 6) - Finishing touches
- jQuery 1.3 : Working with numeric form data (part 5)
- jQuery 1.3 : Working with numeric form data (part 4) - Dealing with decimal places
- jQuery 1.3 : Working with numeric form data (part 3) - Parsing and formatting currency
- jQuery 1.3 : Working with numeric form data (part 2)
- jQuery 1.3 : Working with numeric form data (part 1) - Shopping cart table structure
- The Art of SEO : Controlling Content with Cookies and Session IDs
- iPad SDK : New Graphics Functionality - We Are All Tool Users (part 5) - The Freehand Tool
- iPad SDK : New Graphics Functionality - We Are All Tool Users (part 4) - The Ellipse and Rectangle Tools
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us